//
//  MenuViewController.m
//  YiShangPin
//
//  Created by 衣尚品1 on 15/3/5.
//  Copyright (c) 2015年 yishangpin2. All rights reserved.
//

#import "MenuViewController.h"
#import "MenuTableViewCell.h"

#import "OrderHistoryVC.h"
#import "ActivityVC.h"
#import "WalletVC.h"

@interface MenuViewController ()
{
    
    NSMutableDictionary *MenuDic;
    NSMutableArray *GroupKey;
    NSMutableArray *OrderHistoryArray;
    NSMutableArray *CustomerSupportArray;
    NSMutableArray *SettingArray;
    
}

#define Color(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]


@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //初始化
    
    GroupKey = [[NSMutableArray alloc]initWithObjects:@"OrderHistory",@"CustomerSupport",@"Setting",nil];
    OrderHistoryArray = [[NSMutableArray alloc]initWithObjects:@"Activity",@"Wallet",@"Order History", nil];
//    OrderHistoryArray = [[NSMutableArray alloc]initWithObjects:@"Search",@"Activity",@"Wallet",@"Shop More",@"Invite Friends",@"Order History", nil];
    CustomerSupportArray = [[NSMutableArray alloc]initWithObjects:@"Contact Us",@"Manage Lists",@"FAQ",@"Refunds & Returns", nil];
    SettingArray = [[NSMutableArray alloc]initWithObjects:@"Rate App",@"Emails",@"Currency Settings",@"Push Notifications",@"Data Control",@"Terms of Service",@"Privacy Policy",@"Return Policy",@"Update Profile",@"Change Profile Picture",@"Change Password",@"Change Email Address",@"Logout",@"Delete Account",@"null", nil];
    
    MenuDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:OrderHistoryArray,@"OrderHistory",CustomerSupportArray,@"CustomerSupport",SettingArray,@"Setting", nil];
    
    self.TableView.showsVerticalScrollIndicator = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}






//每个区的HeaderCell（顶部）的高度
#pragma mark - tableView
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30.0;
}
////每个区的FootCell（底部）的高度
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    if (section == 2) {
//        return 78.0;
//    }
//    else
//        return 0;
//    
//}
//
////每个区的FootCell（底部）的高度
//
//-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//    
//    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)];
//    
//    //统一设置颜色
//    UIColor *LabelColor = [UIColor lightGrayColor];
//    //统一设置字体
//    UIFont *LabelFont = [UIFont fontWithName:@"TimesNewRomanPS-ItalicMT" size:12];
//    
//    
//    UILabel *Label0 = [[UILabel alloc] initWithFrame:CGRectMake(13, 5, 250, 20)];
//    Label0.backgroundColor = [UIColor clearColor];
//    Label0.textColor = LabelColor;
//    Label0.font = LabelFont;
//    Label0.text = @"Logged in via Email";
//    
//    UILabel *Label1 = [[UILabel alloc] initWithFrame:CGRectMake(13, 20, 250, 20)];
//    Label1.backgroundColor = [UIColor clearColor];
//    Label1.textColor = LabelColor;
//    Label1.font = LabelFont;
//    Label1.text = @"Email:leevisia@gmail.com";
//    
//    UILabel *Label2 = [[UILabel alloc] initWithFrame:CGRectMake(13, 35, 250, 20)];
//    Label2.backgroundColor = [UIColor clearColor];
//    Label2.textColor = LabelColor;
//    Label2.font = LabelFont;
//    Label2.text = @"User ID:23424-530353450635F345d35e";
//    
//    UILabel *Label3 = [[UILabel alloc] initWithFrame:CGRectMake(13, 50, 250, 20)];
//    Label3.backgroundColor = [UIColor clearColor];
//    Label3.textColor = LabelColor;
//    Label3.font = LabelFont;
//    Label3.text = @"Wish v3.9.0";
//    
//    [footView addSubview:Label0];
//    [footView addSubview:Label1];
//    [footView addSubview:Label2];
//    [footView addSubview:Label3];
//    footView.backgroundColor = Color(240,240,240);
//    return footView;
//}

//每个区的HeaderCell（顶部）的内容
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
    bgView.backgroundColor = Color(240,240,240);
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 4, 250, 20)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = [UIColor grayColor];
    titleLabel.font = [UIFont systemFontOfSize:12];
    titleLabel.font = [UIFont fontWithName:@"TimesNewRomanPS-BoldItalicMT" size:18];
    
    titleLabel.text = GroupKey[section];
    
    [bgView addSubview:titleLabel];
    
    return bgView;
}


//区的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return GroupKey.count;
}


//每个区里对应的Cell的个数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *key=[GroupKey objectAtIndex:section];
    NSArray *Section=[MenuDic objectForKey:key];
    return Section.count;
}

//Cell的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 2 && indexPath.row == SettingArray.count-1) {
        MenuTableViewCell *memucell = [tableView dequeueReusableCellWithIdentifier:@"memucell"];
        
        return  memucell;
        
        
        
    }
    
    
    else{
        
    static NSString *CellIdentifier = @"Cell";
    NSString *key = [GroupKey objectAtIndex:indexPath.section];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    

    
    cell.textLabel.text = [[MenuDic objectForKey:key] objectAtIndex:indexPath.row];

        return cell;}
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 2 && indexPath.row == SettingArray.count-1) {
        return 77;
    }
    else
        return 40;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *key = [GroupKey objectAtIndex:indexPath.section];
    if ([key isEqualToString:@"OrderHistory"] && [OrderHistoryArray[indexPath.row] isEqualToString:@"Order History"]) {
        OrderHistoryVC *orderhistory = [self.storyboard instantiateViewControllerWithIdentifier:@"orderhistoryvc"];
        [self.navigationController pushViewController:orderhistory animated:YES];
        
    }
    
    if ([key isEqualToString:@"OrderHistory"] && [OrderHistoryArray[indexPath.row] isEqualToString:@"Activity"]) {
        ActivityVC *activityVC = [self.storyboard instantiateViewControllerWithIdentifier:@"activityVC"];
        [self.navigationController pushViewController:activityVC animated:YES];
        
    }

    if ([key isEqualToString:@"OrderHistory"] && [OrderHistoryArray[indexPath.row] isEqualToString:@"Wallet"]) {
        WalletVC *walletVC = [self.storyboard instantiateViewControllerWithIdentifier:@"walletVC"];
        [self.navigationController pushViewController:walletVC animated:YES];
        
    }
}
@end
